import React, { Component } from 'react';
import { Menu, Dropdown, message } from 'antd';
import axios from 'axios'

import './index.less';

class Header extends Component {
  constructor(props) {
    super(props);

    this.doLogin = this.doLogin.bind(this);
    this.doRegister = this.doRegister.bind(this);
    this.doExit = this.doExit.bind(this);
  }
  // 跳转 诺诺云办公 用户登录
  doLogin() {
    // this.props.doLogin(true);
    window.location.assign("https://u.jss.com.cn/Contents/usercenter/allow/login/login.jsp?redirecturl=jskpcard")

  }
  // 跳转 诺诺云办公 用户注册
  doRegister() {
    // this.props.doRegister(true);
    window.location.assign("https://u.jss.com.cn/Contents/usercenter/allow/register/register.jsp?redirecturl=jskpcard")
  }
  // 退出登录
  doExit() {
    axios.get('/nuonuo/invoice/ssoLogout.action')
      .then(res => {
        if (res.code === 'S0000') {
          this.props.signOut()
        } else {
          message.warning('退出登录失败！')
        }
      })
      .catch(error => {
        throw (error)
      })
  }

  render() {
    const { isLogin, className, searchbox, userInfo } = this.props;
    // console.log(userInfo);

    const menu = (
      <Menu>
        <Menu.Item key="0">
          <a href={window.dowloadjskpbai} target="_blank" rel='noopener noreferrer' style={{ fontSize: '13px', padding: '0px 12px' }}>航信版下载（白盘）</a>
        </Menu.Item>
        <Menu.Item key="1">
          <a href={window.dowloadjskphei} target="_blank" rel='noopener noreferrer' style={{ fontSize: '13px', padding: '0px 12px' }}>百旺版下载（黑盘）</a>
        </Menu.Item>
      </Menu>
    )

    return (
      <div className={`header-container${className ? ` ${className}` : ''} `} >
        <div className="header-content">
          <a href="./index.html" className='logo'>
            <img src='//nnfw.jss.com.cn/770FF64BEEF64680B1BE88261A6384A5/logo.svg' width="130" height="32" alt="logo" />
          </a>

          {/* 搜索框 */}
          {searchbox}

          <div className="header-navbar">
            <div className="dowload_miyao float_left">
              <Dropdown overlay={menu} trigger={['click']}>
                <a className="dowload_miyao_text">下载极速开票</a>
              </Dropdown>
              <span>|</span>
              <a href="https://jss.com.cn/Contents/portal/allow/forage/step1/index.ftl" target="_blank" rel="noopener noreferrer" className="dowload_miyao_text">桌牌申请</a><span>|</span>
              <a href={window.dowloadjskpDoc} className="dowload_miyao_text">极速开票使用手册</a>
            </div>
            {
              isLogin ?
                <div className="float_left">
                  <span>欢迎您，{userInfo && (userInfo.cPhone ? userInfo.cPhone : userInfo.cUsername)}</span>
                  <span className="pointer" onClick={this.doExit}>退出</span>
                </div>
                :
                <div className="float_left">
                  <span className="pointer" onClick={this.doLogin}>登录</span>
                  <span className="pointer" onClick={this.doRegister}>注册</span>
                </div>
            }
          </div>
        </div>
      </div>
    )
  }
}
export default Header